package com.huluobo.mvvmdemo1903a.mvvm.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.huluobo.mvvmdemo1903a.mvvm.model.User;

/**
 * Created by lc on 2021/11/22.
 */
public class LoginViewModel extends ViewModel {
    private User user;
    private MutableLiveData<Boolean> isLoginSuccessful;

    public LoginViewModel() {
        this.isLoginSuccessful = new MutableLiveData<>();
        user = new User();
    }

    public MutableLiveData<Boolean> getIsLoginSuccessful() {
        return isLoginSuccessful;
    }

    public void setIsLoginSuccessful(boolean isLoginSuccessful) {
        this.isLoginSuccessful.postValue(isLoginSuccessful);
    }

    public void login(String userName, String password) {
        if (userName.equals("lc") && password.equals("123")) {
            user.setUserName(userName);
            user.setPassword(password);
            setIsLoginSuccessful(true);
        } else {
            setIsLoginSuccessful(false);
        }
    }

    public String getUserName() {
        return user.getUserName();
    }
}
